package com.api.qfengx.dev.bean;

import java.io.Serializable;

/**
 * 二开用接口结果响应类
 */
public class Result<T> implements Serializable {

    private static final long serialVersionUID = -1709744999685186288L;

    private String api_status;
    private String message;
    private Integer code;
    private T data;

    public Integer getCode() {
        return code;
    }

    public Result<T> setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getApi_status() {
        return api_status;
    }

    public Result<T> setApi_status(String api_status) {
        this.api_status = api_status;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Result<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>().setApi_status("1")
                .setMessage("操作成功")
                .setData(data);
    }

    public static Result success() {
        return new Result().setApi_status("1")
                .setMessage("操作成功");
    }

    public static Result fail(String message) {
        return new Result().setApi_status("0").setMessage(message);
    }

    public static Result fail() {
        return fail("操作失败");
    }

    public static Result exception(String message) {
        return new Result().setApi_status("1001").setMessage(message);
    }

    public static Result exception() {
        return exception("操作异常");
    }

    public static Result paramErr(String message) {
        return new Result().setApi_status("1002").setMessage(message);
    }

    public static Result paramErr() {
        return paramErr("参数异常");
    }
}